using System;
using System.Collections.Generic;
using System.Text;

namespace CDE_Model
{
    /// <summary>
    /// A class that represents XML 1.1 Elements
    /// This class is obsolete!!!
    /// </summary>
    [Serializable]
    [Obsolete]
    public class Element
    {
        #region Fields

        private List<Element> _ancestors;
        private List<Element> _descendants;
        private Element _parent;
        private List<Element> _children;
        private String _genericIdentifier;
        private String _content;
        private List<Attribute> _attributes;

        #endregion

        #region Properties

        public List<Element> Ancestors
        {
            get { return _ancestors; }
            set { _ancestors = value; }
        }

        public List<Element> Descendants
        {
            get { return _descendants; }
            set { _descendants = value; }
        }

        public Element Parent
        {
            get { return _parent; }
            set { _parent = value; }
        }

        public List<Element> Children
        {
            get { return _children; }
            set { _children = value; }
        }

        public String GenericIdentifier
        {
            get { return _genericIdentifier; }
            set { _genericIdentifier = value; }
        }

        public String Content
        {
            get { return _content; }
            set { _content = value; }
        }

        public List<Attribute> Attributes
        {
            get { return _attributes; }
            set { _attributes = value; }
        }

        #endregion

        #region Constructors

        public Element(Document _doc)
        {
            //_doc.A = this;

            Parent = null;

            Ancestors = new List<Element>();

            Children = new List<Element>();

            Descendants = new List<Element>();
        }

        public Element(Element _ele)
        {
            Parent = _ele;

            Ancestors = _ele.Ancestors;
            Ancestors.Add(_ele);

            Children = new List<Element>();
            _ele.Children.Add(this);

            Descendants = new List<Element>();
        }

        #endregion

        #region Methods

        /// <summary>
        /// Add an attribute to the Attributes of this element
        /// </summary>
        /// <param name="_att">Attribute to add</param>
        /// <returns>If the action was successful</returns>
        public bool AddAttribute(Attribute _att)
        {
            Attributes.Add(_att);

            if (Attributes.Contains(_att))
                return true;
            else
                return false;
        }

        /// <summary>
        /// Remove an attribute from the Attributes of this element
        /// </summary>
        /// <param name="_att">Attribute to remove</param>
        /// <returns>If the action was successful</returns>
        public bool RemoveAttribute(Attribute _att)
        {
            Attributes.Remove(_att);

            if (Attributes.Contains(_att))
                return false;
            else
                return true;
        }

        public override string ToString()
        {
            String subTree = "Element: " + GenericIdentifier + '\n';

            foreach (Element c in Children)
            {
                subTree += c.ToString();
            }

            return subTree;
        }

        #endregion

    }
}
